#include "scylla.h"


scylla::scylla()
{
    ui = new Ui_Appreciate();
	ui->setupUi(this);
    qsrand(QTime::currentTime().msec());
    timer = new QTimer(this);
    timer->setInterval(100);
    flag = false;
    timer->start();
    QObject::connect(timer,SIGNAL(timeout()),this,SLOT(repaint()));
    QObject::connect(ui->start,SIGNAL(clicked()),this,SLOT(changeEvent()));
    QObject::connect(ui->stop,SIGNAL(clicked()),this,SLOT(changeEvent()));

}

scylla::~scylla()
{
	delete(ui);
}

void scylla::paintEvent(QPaintEvent *)
{
    QPainter qp(this);
    if(flag == true)
    {
        /* 随机切换图片 */
        int num = qrand()%5 + 1;
        QString imgstr = "./img/";
        imgstr += QString::number(num);
        imgstr += ".jpg";
        img.load(imgstr);
        qp.drawImage(0,0,img);
    }
    qp.drawImage(0,0,img);
}


void scylla::changeEvent()
{
    if(sender()->objectName() == "start")
    {
        flag = true;
    }
    if(sender()->objectName() == "stop")
    {
        flag = false;
    }
}







